//
//  VMCMiscApi.m
//  vmcshop
//
//  Created by bigknife on 14/11/7.
//  Copyright (c) 2014年 idongler. All rights reserved.
//

#import "VMCMiscApi.h"
const SmsType SmsTypeSignUp = @"signup";
const SmsType SmsTypeResetPassword = @"resetpassword";

@implementation VMCMiscApi
+(instancetype) sharedInstance {
    static VMCMiscApi *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
    });
    return instance;
}

-(void) sendSmsVCodeToMobile:(NSString *)mobile
                    withType:(SmsType)type
                    callback:(API_CALLBACK)callback{
    ApiRequest *request = [ApiRequest requestWithBizData:@{
                                                           @"mobile" : EMPTY_IF_NIL(mobile),
                                                           @"smsType" :EMPTY_IF_NIL(type)
                                                           }];
    [self postApi:@"emc_passport/sms_vcode" andRequest:request callback:callback];

}

-(void) loadWidgets:(API_CALLBACK)callback{
    ApiRequest *request = [ApiRequest requestWithBizData:@{}];
    [self postApi:@"emc_index/widgets" andRequest:request callback:callback];
}

-(void) loadRegionsWithParent:(NSString *)parentRegionId callback:(API_CALLBACK)callback {
	ApiRequest *request = [ApiRequest requestWithBizData:parentRegionId ? @{@"parentRegionId" : EMPTY_IF_NIL(parentRegionId)} : nil];
	[self postApi:@"emc_tools/regions" andRequest:request callback:callback];
}

-(void) loadRegionsWithAddressID:(NSString *)addressID callback:(API_CALLBACK)callback
{
	ApiRequest *request = [ApiRequest requestWithBizData:addressID ? @{@"address" : EMPTY_IF_NIL(addressID)} : nil];
	[self postApi:@"emc_store/get" andRequest:request callback:callback];
}

//-(void) saveShippingAddress:(VMCShippingAddressDomain *)shippingAddress
//				   callback:(API_CALLBACK)callback{
//	NSDictionary *dict = [RMMapper dictionaryForObject:shippingAddress];
//	ApiRequest *request = [ApiRequest requestWithBizData:dict];
//	[self postApi:@"emc_member/address_save" andRequest:request callback:callback];
//}
-(void) loadMyShippingAddressListWithCallback:(API_CALLBACK)callback{
	ApiRequest *request = [ApiRequest requestWithBizData:@{}];
	[self postApi:@"emc_member/address_list" andRequest:request callback:callback];
}

-(void) setShippingAddress:(NSString *)shippingAddressId toBeDefaultWithCallback:(API_CALLBACK)callback{
	ApiRequest *request = [ApiRequest requestWithBizData:@{@"id": EMPTY_IF_NIL(shippingAddressId)}];
	[self postApi:@"emc_member/address_default" andRequest:request callback:callback];

}

-(void)deleteAddress:(NSString *)AdressId formMyFavWithCallback:(API_CALLBACK)callback{
	ApiRequest *request = [ApiRequest requestWithBizData:@{@"id" : EMPTY_IF_NIL(AdressId)}];
	[self postApi:@"emc_member/address_remove" andRequest:request callback:callback];
}

@end
